/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Stud_grade",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.MyTable.IServices;
using Microsoft.AspNetCore.Authorization;
using VOL.MyTable.IRepositories;
using VOL.MyTable.Repositories;
using VOL.Core.Utilities;

namespace VOL.MyTable.Controllers
{
    public partial class Stud_gradeController
    {
        private readonly IStud_gradeService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Stud_gradeController(
            IStud_gradeService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        [HttpPost, Route("UpdateStudGrade"),AllowAnonymous]
        public ActionResult UpdateStudGrade([FromBody]Stud_grade sg)
        {
            WebResponseContent webResponse = new WebResponseContent();
            IStud_gradeRepository repository = Stud_gradeRepository.Instance;
           // Console.WriteLine("===="+sg.stud_grade_id+"+++++");
            if (sg.stud_grade_id.ToString() == "0")//0表示stud_grade_id为空，就增加数据，否则就更新数据
            {
                repository.Add(sg, true);
            }
            else
            {
                repository.Update(sg, true);
            }
            
            return  Json(webResponse.OK("数据修改成功"));
        }


        /// <summary>
        /// 前台与后台数据一起删除，就不需要刷新客户端界面了。
        /// </summary>
        /// <param name="sg"></param>
        /// <returns></returns>
        [HttpPost, Route("DeleteStudGrade"), AllowAnonymous]
        public ActionResult DeleteStudGrade([FromBody] Stud_grade sg)
        {
            WebResponseContent webResponse = new WebResponseContent();
            IStud_gradeRepository repository = Stud_gradeRepository.Instance;
           // Console.WriteLine(sg.class_name+"S数据");
            repository.Delete(sg, true);
            return Json(webResponse.OK("数据删除成功！"));
        }
    }
}
